package com.jbit.dm212.controller;

import cn.hutool.core.bean.BeanUtil;
import com.jbit.dm212.common.ResponseResult;
import com.jbit.dm212.common.ResponseResultUtils;
import com.jbit.dm212.common.UserUtil;
import com.jbit.dm212.entity.po.DmItemComment;
import com.jbit.dm212.entity.po.DmUser;
import com.jbit.dm212.entity.vo.DmItemCommentVO;
import com.jbit.dm212.service.DmItemCommentService;
import org.apache.catalina.User;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.Calendar;

@RestController
@RequestMapping("/item/api/v")
public class DmItemVerifyController {
    @Resource
    private DmItemCommentService itemCommentService;
    @PostMapping("/commitItemComment")
    public ResponseResult commitItemComment(@RequestBody DmItemCommentVO itemCommentVO){
        DmItemComment itemComment = BeanUtil.toBean(itemCommentVO,DmItemComment.class);
        DmUser user = UserUtil.getUser();
        itemComment.setUserId(user.getId());
        itemComment.setContent(itemCommentVO.getComment());
        itemComment.setCreatedTime(Calendar.getInstance().getTime());
        itemCommentService.addComment(itemComment);
        return ResponseResultUtils.sendSuccess();
    }
}
